﻿//
//
// 版权所有 (c) 2021-2023 JR  
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using AspNetCoreRateLimit;
using FluentEmail.Core;
using Furion.FriendlyException;
using Microsoft.CodeAnalysis.FlowAnalysis;
using Minio.DataModel;
using Nest;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EMC.VISITOR.Application;


/// <summary>
/// 查询结果
/// </summary>
public static class ServiceSelectExtend
{




    public static async Task<SqlSugarPagedList<OUT>> CustomToSelect<T, OUT>(this ISugarQueryable<T> query, BasePageInput input)
    {
        await Task.CompletedTask;
        return default(SqlSugarPagedList<OUT>);
    }
    public static async Task<List<OUT>> CustomToSelectExport<T, OUT>(this ISugarQueryable<T> query, BasePageInput input)
    {
        var exprotQuery = CustomToSelect<T, OUT>(query, input);
        await Task.CompletedTask;
        return default(List<OUT>);
    }
    /// <summary>
    /// 是否使用自定义查询，默认不使用，默认使用代码自动生成的查询
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="query"></param>
    /// <returns></returns>
    public static bool UseCustomeSelectFlag<T>(this ISugarQueryable<T> query)
    {
        return false;
    }
}
/// <summary>
/// 查询Where条件配置
/// </summary>
public static class ServiceQueryWhereExtend
{
    public static ISugarQueryable<T> CustomWhere<T>(this ISugarQueryable<T> query, BasePageInput input)
    {
        return query.MyFilters(input);
    }

    public static ISugarQueryable<T> MyFilters<T>(this ISugarQueryable<T> query, BasePageInput input)
    {
        if (input.Filters != null && input.Filters.Count > 0)
        {
            var cm = new List<IConditionalModel>();
            for (int i = 0; i < input.Filters.Count; i++)
            {
                var every = input.Filters[i];
                if (!every[0].IsNullOrEmpty() && !every[1].IsNullOrEmpty() && !every[2].IsNullOrEmpty())
                    cm.Add(new ConditionalModel { FieldName = every[0], ConditionalType = SqlSugarSetup.GetConditionalType(every[1]), FieldValue = every[2] });
            }
            if (cm.Count > 0)
                return query.Where(cm);
        }
        return query;
    }
}
/// <summary>
/// 查询结果配置
/// </summary>
public static class ServiceQueryToPagedExtend
{
    #region 删除 2023-11-24
    ///// <summary>
    ///// 派工单开完工页面
    ///// </summary>
    ///// <param name="query"></param>
    ///// <param name="input"></param>
    ///// <returns></returns>
    //public static async Task<SqlSugarPagedList<MO_PO_WorkOrderOutput>> CustomToPagedListAsync(this ISugarQueryable<MO_PO_WorkOrderOutput> query, BasePageInput input)
    //{
    //    var data = await query.CustomToPagedListAsync<MO_PO_WorkOrderOutput>(input);
    //    if (!input.FrontPath.IsNullOrEmpty() && input.FrontPath.Contains(GlobalCustomSettings.MPWorkOrderPage))
    //    {
    //        data.Items.ForEach(r =>
    //        {
    //            r.Qualifiedqty = 0;
    //            r.Scrapqty = 0;
    //        });
    //    }
    //    return data;
    //} 
    #endregion
    public static async Task<SqlSugarPagedList<T>> CustomToPagedListAsync<T>(this ISugarQueryable<T> query, BasePageInput input) where T : class
    {
        return await query.ToPagedListAsync(input.Page, input.PageSize);
    }
}
/// <summary>
/// 查询排序配置
/// </summary>
public static class ServiceOrderExtend
{
    public static ISugarQueryable<T> CustomeOrder<T>(this ISugarQueryable<T> query, BasePageInput input = null, string prefix = null) where T : class
    {
        if (input != null && !input.Field.IsNullOrEmpty())
        {
            if (prefix == null)
                return query.OrderBuilder(input);
            else
                return query.OrderBuilder(input, "");
        }

        return query;
    }
}
/// <summary>
/// 下拉菜单查询配置
/// </summary>
public static class DropDownExtend
{
    public static ISugarQueryable<T> DropDownQuery<T>(this ISugarQueryable<T> query) where T : class
    {
        return query;
    }
}

/// <summary>
/// 下拉框查询结果配置
/// </summary>
public static class UseDropDownCustomeSelectExtend
{


    public static async Task<dynamic> UseDropDownCustomeSelect<T>(this ISugarQueryable<T> query, object obj) where T : class
    {
        await Task.CompletedTask;
        return default(dynamic);
    }
    public static bool UseDropDownCustomeSelectFlag<T>(this ISugarQueryable<T> query) { return false; }
}



